package Com.StudentControlSystem;

import java.util.*;

public class AddStudent{

    public static void addStudent() {
        System.out.println("---请输入学生信息----");
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入学生姓名");
        String name = sc.next();
        String ID;
        do {
            System.out.println("请输入学生学号");
            ID = sc.next().trim();
            // 检查学号是否已存在
            if (StudentData.getStudentMap().containsKey(ID)) {
                System.out.println("学号已存在！请重新输入！");
            }
        }
        while (StudentData.getStudentMap().containsKey(ID));

        System.out.println("请输入学生年龄");
        int age = sc.nextInt();
        System.out.println("请输入学生地址");
        String address = sc.next();
        Student student = new Student(name, ID, age, address);
        StudentData.addStudent(student); // 使用 StudentData 统一管理数据
        System.out.println("添加学生信息成功！ 学生: " + student);
    }
}
